<%@ page language="java" contentType="text/html; charset=UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<html>
<head>
	<meta charset="utf-8" />
	<meta name="keywords" content="pinpin社保" />
	<meta name="description" content="pinpin社保" />
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
    <meta name="renderer" content="webkit" />
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>社保运营后台-订单管理</title>
	<%@ include file="/WEB-INF/jsp/common/common.jsp" %>
</head>
<body>
	<div id="wrapper">
        <%@ include file="/WEB-INF/jsp/common/menu.jsp" %>
        <div id="page-wrapper">
        	<div class="row">
                <div class="col-lg-12">
                    <!-- 路径导航 -->
                    <ol class="breadcrumb">
				      <li>社保后台</li>
				      <li class="active">订单查询</li>
				      <li><a href="${kefu_dec_query_uri }">减员查询</a></li>
				    </ol>
                </div>
            </div>
            <div class="row">
            	<div class="col-lg-12">
            		<div class="panel panel-default">
            			<div class="panel-body">
        			    	<div class="form-inline dt-bootstrap no-footer">
        			    		<!-- 表单查询 -->
        			    		<form action="" id="queryOrderKefuForm" method="POST">
        			    		<div class="row">
        			    			<div class="col-lg-12">
        			    				<label class="checkbox-inline">
        			    				<input type="text" class="form-control" name="order_no" placeholder="请输入订单号" value="${payOrderQueryForm.order_no }">
                                        <input type="text" class="form-control" name="id_card" placeholder="请输入身份证" value="${payOrderQueryForm.id_card }">
                                        <input type="text" class="form-control" name="user_name" placeholder="请输入购买人姓名" value="${payOrderQueryForm.user_name }">
                                        <input type="text" class="form-control" name="pay_user" placeholder="请输入购买账号" value="${payOrderQueryForm.pay_user }">
                                        </label>
        			    			    <input type="submit" id="queryBtn" class="btn btn-primary" value="查 询">
        			    			    <input type="button" id="resetBtn" class="btn btn-primary" value="重 置">
        			    			</div>
        			    			<div class="col-lg-12">
        			    				<label class="checkbox-inline" style="margin-top:10px">多个身份证：
        			    			    <textarea name="idcards" cols="100" class="form-control" placeholder="用于批量提供多个身份证的数据查询。多个以 英文逗号(,) 间隔; 忽略其它查询条件值。">${payOrderQueryForm.idcards }</textarea>
        			    			     </label>
        			    				<label class="checkbox-inline" style="margin-top:10px">多&nbsp;个&nbsp;帐&nbsp;号：
        			    			    <textarea name="payusers" cols="100" class="form-control" placeholder="用于批量提供多个手机帐号的数据查询。多个以 英文逗号(,) 间隔; 忽略其它查询关键字">${payOrderQueryForm.payusers }</textarea>
        			    			    </label>
        			    			 </div>
        			    			<div class="col-lg-12">
        			    			 </div>
        			    		</div>
        			    		</form>
        			    		<hr />
        			    		<!-- 分页 -->
        			    		<div class="row">
        			    			<div class="col-lg-2">
										<input type="button" onclick="toAskRefund()" class="btn btn-primary" value="< 批量申请退款 >">
        			    			</div>
        			    			<div class="col-lg-2">
										<input type="button" onclick="toDec()" class="btn btn-primary" value="< 批量申请减员  >">
        			    			</div>
        			    			<div class="col-lg-8">
        			    				<jsp:include page="/WEB-INF/jsp/common/page.jsp">
        			    					<jsp:param name="formId" value="queryOrderKefuForm"/>
        			    				</jsp:include>
        			    			</div>
        			    		</div>
        			    		
        			    		<!-- 表格列表 -->
        			    		<div class="row">
        			    			<div class="col-lg-12 width-auto">
        			    				<table id="dataContent" class="table table-striped table-bordered table-hover no-footer" role="grid">
        			    					<thead>
        			    						<tr><th><label><input type="checkbox" id="pids">全选</label></th>
                                                    <th>城市</th>
                                                    <th>类型</th>
                                                    <th>参保人 &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
                                                    	手机帐号 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
                                                    	身份证</th>
													<th>状态</th>
                                                    <th>月份 &nbsp;&nbsp;&nbsp; 月数</th>
                                                    <th>补缴</th>
                                                    <th>总金额</th>
                                                    <th>(工资基数)当月该付</th>
                                                    <th>当月实付</th>
                                                    <th>预收费</th>
                                                    <th>用券</th>
                                                    <th>需补差额</th>
                                                    <th>补退款</th>
                                                    <th>手机端提示</th>
                                                    <th>时间</th>
                                                    <th>备注</th>
                                                    <th>首次？</th>
													<th>回访日志</th>
                                                    <th>支付相关</th>
                                                </tr>
        			    					</thead>
        			    					<tbody>
                                            <c:choose>
       			    						<c:when test="${empty pageModel.recordList }">
												<c:if test="${isQuery eq true}"><tr role="row"><td colspan="20">没有找到相关记录 请填写查询条件</td></tr></c:if>
       			    						</c:when>
       			    						<c:otherwise>
        			    					<c:forEach items="${pageModel.recordList }" var="order">
	        			    					<c:if test="${order.status == 11 }"><c:set var="sign_color" value="#F96"></c:set></c:if>
			        			    				<c:if test="${order.added == 1 && order.manual == 0 }"><c:set var="sign_color" value="#C99"></c:set></c:if>
		        			    					<c:if test="${order.sign_status > 0 }">
			        			    					<c:if test="${order.sign_status == 106 }"><c:set var="sign_color" value="#FF6"></c:set></c:if>
			        			    					<c:if test="${order.sign_status == 111 }"><c:set var="sign_color" value="#6CC"></c:set></c:if>
		        			    					</c:if>
	        			    					<tr role="row" style="background-color:${sign_color }">
        			    							<c:set var="sign_color" value=""/>
        			    							<td><input type="checkbox" id="pids_${order.order_no }" name="pids" value="${order.order_no }" />
        			    								<input type="hidden" id="order_pay_uid" value="${order.pay_uid }" />
        			    								<input type="hidden" id="order_id_card" value="${order.id_card }" />
        			    							</td>
        			    							<td>
	                                                    <c:forEach var="city" items="${cityList }"><c:if test="${order.city_code eq city.id }"><a target="_blank" href="${order.pay_for == 1 ? shebao_view_uri : fund_view_uri }?cid=${order.cid }">${city.name } ${order.param_name }</a><c:set var="exitId" value="0"></c:set></c:if></c:forEach>
        			    							</td>
                                                    <td style="text-align:right">
	                                                    <c:if test="${order.pay_for == 1 }">
                                                			社保<c:if test="${order.new_card == 1 }">(新办卡) &nbsp;</c:if>
                                                			<c:if test="${order.new_card == 2 }">(补办卡) &nbsp;</c:if>
                                       				 	</c:if>
                                       				 	<c:if test="${order.pay_for == 2 }">
                                       				 		公积金 &nbsp;
                                       				 	</c:if>&nbsp;
	                                                    <c:if test="${order.hukou == 1 }">本地城镇</c:if>
	                                                    <c:if test="${order.hukou == 2 }">本地农村</c:if>
	                                                    <c:if test="${order.hukou == 3 }">外市城镇</c:if>
	                                                    <c:if test="${order.hukou == 4 }">外市农村</c:if>
                                                    </td>
                                                    <td style="text-align:right">
                                                    	${order.user_name } &nbsp; 
                                                    	${order.gender==0? '女' : '男' } &nbsp;
                                                    	${order.pay_user } &nbsp;
                                                    	<a target="_blank" href="${view_idcard_uri }?id_card=${order.id_card }&uid=${order.pay_uid }">
                                                    	${order.id_card }
                                                    	</a>
                                                    </td>
												<td>
													<c:forEach var="ostatus" items="${orderStatus }">
														<c:if test="${order.status == ostatus.num }">
															<a href="javascript:logList('${order.order_no }');">${ostatus.name }</a>
															<c:set var="exitId" value="0"></c:set> <!-- break -->
														</c:if>
													</c:forEach>
												</td>
                                                    <td>
	                                                    <span id="m${order.order_no }" style="display:none">${order.for_month }</span>
	                                                    <fmt:formatNumber pattern="#" type="number" value="${(order.for_month - (order.for_month mod 100))/100 }"/>年${order.for_month mod 100 }月
	                                                    &nbsp;&nbsp;${order.month_num }
                                                    </td>
													<td>
														<c:if test="${order.added == 1}">
															<c:if test="${order.manual == 0}">
																补缴订单
															</c:if>
		                                                    <c:if test="${order.manual > 0}">
		                                                    	<label>${order.manual_type == 0 ? '增员' : '在保' } ${order.manual }</label>
															</c:if>
														</c:if>
													</td>
                                                    <td>￥${order.total_fee }</td>
													<td style="text-align:right">
														<c:if test="${order.pay_for == 1}">
															<c:set var="order_price" value="${order.shebaos + order.shebao_charge + order.card_charge}"/>
														</c:if>
														<c:if test="${order.pay_for == 2}">
															<c:set var="order_price" value="${ order.funds + order.fund_charge }"/>
															(￥${order.fund_salary})
														</c:if>
														￥${order_price} 
													</td>
													<td>￥${order_price - order.coupon_price }</td>
													<td>￥${order.pre_charge}</td>
													<td>
														<c:if test="${not empty order.coupon_code}">用券</c:if>
													</td>
													<td ${order.needRepayAmount>0?'style="background-color:#F99"':'' }  title="此用户历史欠费总额">
                                                    <c:if test="${order.needRepayAmount > 0 }">
	                                                    <a href="${repay_list_uri }?id_card=${order.id_card }" target="_blank">
	                                                    	￥${order.needRepayAmount }
	                                                    </a>
	                                                </c:if>
	                                                </td>
													<td>
														${order.refundType == 1 ? -order_price : order.repayAmount - order.refundAmount}
													</td>
													<td>${order.app_remark }</td>
													<td><fmt:formatDate value="${order.pay_time }" pattern="yyyy-MM-dd HH:mm:ss"/></td>
													<td>${order.note }</td>
													<td>${order.first_buy == 1 ? '是' : '' }</td>
													<td><a href="javascript:hfLogList('${order.id_card}','${order.city_code}');">回访日志</a>&nbsp;</td>
													<td id="td${order.order_no }">
	                                                	<a href="javascript:logList('${order.order_no }');">${order.order_no }</a>&nbsp;&nbsp;
                                            			${order.pay_channel == 1 ? '微信支付  ' : '支付宝支付  '} &nbsp;&nbsp;
                                                    	支付流水号：${order.pay_no }&nbsp;&nbsp;
                                                    	交易号：${order.trade_no }
													</td>
        			    						</tr>
        			    					</c:forEach>
		        			    			</c:otherwise>
		        			    			</c:choose>
        			    					</tbody>
        			    				</table>
        			    			</div>
        			    		</div>
        			    		<!-- 分页 -->
                                <br/>
        			    		<div class="row">
        			    			<div class="col-lg-2">
        			    			</div>
        			    			<div class="col-lg-10">
        								<jsp:include page="/WEB-INF/jsp/common/page.jsp">
        			    					<jsp:param name="formId" value="queryOrderKefuForm"/>
        			    				</jsp:include>
        			    			</div>
        			    		</div>
        			    	</div>
            			</div>
            		</div>
            	</div>
            </div>
        </div>
	</div>

	<div id="refundBox" style="display:none;width:500px">
		<div class="alert alert-info">
			<ul>
				<li><b>操作月份</b> 之前的订单, 不能操作 [申请退款].</li>
				<li>日期在截止日期的前 4 天之外, 只当前 <b>操作月份</b> 的订单可操作 [申请退款].</li>
				<li>大于当前 <b>操作月份</b> 的订单可操作 [申请退款].</li>
			</ul>
		</div>
		<form action="" name="refundForm" id="refundForm" method="post">
			<label class="checkbox-inline" style="padding-bottom:10px">
				<input type="radio" name="refundType" value="已有新单位缴费. ">已有新单位缴费</label><br/>
			<label class="checkbox-inline" style="padding-bottom:10px">
				<input type="radio" name="refundType" value="填写信息有误，重新下单. ">填写信息有误，重新下单</label><br/>
			<label class="checkbox-inline" style="padding-bottom:10px">
				<input type="radio" name="refundType" value="在领失业救济，不能参保. ">在领失业救济，不能参保</label><br/>
			<label class="checkbox-inline" style="padding-bottom:10px">
				<input type="radio" name="refundType" value="其他原因. ">其他原因</label><br/>

			<input type="text" class="form-control" id="reason" name="reason" placeholder="填写退款原因 (120字内)" style="margin-left:25px; width: 260px;">
			<input type="hidden" class="form-control" id="order_nos" name="order_nos">
			<hr>
			<button type="button" onclick="javascript:askRefund();" class="btn btn-primary" style="margin-left: 180px;">确定要求退款</button>
		</form>
	</div>
<div id="logListBox" style="display:none;width:660px">
	<table class="table table-striped table-bordered table-hover no-footer" role="grid">
		<thead>
			<tr>
				<th>操作人</th>
                <th>描述</th>
                <th>时间</th>
               </tr>
		</thead>
		<tbody id="logListTbody">
			<!-- <tr role="row"> <td>111</td> <td>111</td> <td>111</td></tr> -->
		</tbody>
	</table>
</div>
<div id="hfLogListBox" style="display:none;width:660px">
	<table class="table table-striped table-bordered table-hover no-footer" role="grid">
		<thead>
		<tr>
			<th>回访人</th>
			<th>回访记录</th>
			<th>回访情况</th>
			<th>回访时间</th>
		</tr>
		</thead>
		<tbody id="hfLogListTbody">
		<!-- <tr role="row"> <td>111</td> <td>111</td> <td>111</td></tr> -->
		</tbody>
	</table>
</div>
<div id="decBox" style="display:none;width:500px">
		<div class="alert alert-info">
			<ul>
				<li>只有核算月份所在月的 <b> 1日 ~ 截止日</b> 能申请减员</li>
				<li>生成的数据可以在 <b>手动减员</b> 菜单查看及处理</li>
				<li>手动申请了减员，系统自动生成短信通知到用户</li>
			</ul>
		</div>
		<form action="" name="decForm" id="decForm" method="post">
			<label class="checkbox-inline" style="padding-bottom:10px">
				<input type="radio" name="urgent" value="0" checked>不加急</label>
			<label class="checkbox-inline" style="padding-bottom:10px">
				<input type="radio" name="urgent" value="1">加急</label><br/>

			<input type="hidden" class="form-control" id="dec_order_nos" name="order_nos">
			<hr>
			<button type="button" onclick="handDec();" class="btn btn-primary" style="margin-left: 180px;">确定手动减员</button>
		</form>
	</div>
</body>
<script lang="javascript">
   $(function(){
		$("#resetBtn").click(function(){ //重置
			$("#queryOrderKefuForm").find("input[type='text'],input[type='select']").val("");
		});
	});

   var view_logs_uri = "${view_logs_uri}";
   var ask_refund_uri = "${ask_refund_uri}";
   var hand_dec_uri = "${hand_dec_uri}";
   var view_hf_logs_uri = "${view_hf_logs_uri}";
   
   function logList(order_no) {
	   var content = document.getElementById("logListBox");
	   dialog({
		   title : '操作日志',
		   content : content,
//		   follow : document.getElementById("td"+order_no),
		   quickClose : true
	   }).show();

	   $.get(view_logs_uri+"?order_no="+order_no, function(result, textStatus) {
		   var _tbody = $("#logListTbody");
		   _tbody.html("");
		   if (result.code != 200) {
			   notice(result.msg);
			   return;
		   }
		   $.each(result.data, function(index, data){
			   _tbody.append('<tr role="row"> <td>'+data.opt_user+'</td> <td>'+data.opt_content+'</td> <td>'
					   +new Date(data.gen_time).format("yyyy-MM-dd hh:mm:ss")+'</td></tr>');
		   });
		});
	}
   function hfLogList(id_card,city_code) {
	   var content = document.getElementById("hfLogListBox");
	   dialog({
		   title : '操作日志',
		   content : content,
//		   follow : document.getElementById("td"+order_no),
		   quickClose : true
	   }).show();

	   $.get(view_hf_logs_uri+"?id_card="+id_card+"&city_code="+city_code, function(result, textStatus) {
		   var _tbody = $("#hfLogListTbody");
		   _tbody.html("");
		   if (result.code != 200) {
			   notice(result.msg);
			   return;
		   }
		   $.each(result.data, function(index, data){
			   _tbody.append('<tr role="row"> <td>'+data.pay_a_return_visit_emp+'</td> <td>'+data.pay_a_return_visit_record+'</td> <td>'
					   + data.pay_a_return_visit_situation + '</td> <td>'
					   +new Date(data.pay_a_return_visit_time).format("yyyy-MM-dd")+'</td></tr>');
		   });
	   });
   }
	function toAskRefund() {
        var orders = "", c = 0;
        $("input[name='pids']:checked").each(function() {
            if (orders == "") {
                orders = $(this).val();
            } else {
                orders += "," + $(this).val();
            }
            c++;
        });
        if (orders == "") {
            smokeAlert(500, "请先在列表的左侧勾选订单");
            return;
        }
        $("#order_nos").val(orders);
		var content = document.getElementById("refundBox");
		dialog({
			title : '申请退款 ' + c + ' 单',
			content : content,
//		   follow : document.getElementById("td"+order_no),
			quickClose : true
		}).show();
    }
	function askRefund() {
        var data = $("#refundForm").serialize();
        jQuery.ajax({
            url : ask_refund_uri,
            data : data,
            type : 'post',
            async : true, // 默认为true 异步
            success : function(result) {
                smokeAlert(result.code, result.msg);
                if (result.code == 200) {
                    window.location.reload();
                }
            }
        });
    }


	function toDec() {
        var orders = "", c = 0;
        $("input[name='pids']:checked").each(function() {
            if (orders == "") {
                orders = $(this).val();
            } else {
                orders += "," + $(this).val();
            }
            c++;
        });
        if (orders == "") {
            smokeAlert(500, "请先在列表的左侧勾选订单");
            return;
        }
        $("#dec_order_nos").val(orders);
		var content = document.getElementById("decBox");
		dialog({
			title : '手动申请减员 ' + c,
			content : content,
//		   follow : document.getElementById("td"+order_no),
			quickClose : true
		}).show();
    }


	function handDec() {
        var data = $("#decForm").serialize();
        jQuery.ajax({
            url : hand_dec_uri,
            data : data,
            type : 'post',
            async : true, // 默认为true 异步
            success : function(result) {
                smokeAlert(result.code, result.msg);
                if (result.code == 200) {
                    //window.location.reload();
                }
            }
        });
    }
</script>
</html>